<?php

namespace App\Http\Middleware;


use Closure;
use Illuminate\Support\Facades\Cookie;

class CityInfo
{

    public function handle($request, Closure $next)
    {
        $citys = \App\Models\RedisCache::GetCacheCitys();
        $hot_cities = [];
        foreach($citys as $key => $value){
            foreach($value as $k => $v){
                if ($v['ishotcity'] == 1){
                    $hot_cities[] = $v;
                }
            }
        }
        $cityobj = json_decode(Cookie::get('city'));
        $ccity   = ["cityname" => "全国", 'cityid' => 0];
        if (!empty($cityobj)){
            $ccity   = ["cityname" => $cityobj->cityname, 'cityid' => $cityobj->id];
        }
        view()->share('cityArr', ['cities'=>$citys,'hot_cities' => $hot_cities, 'ccity' => $ccity]);
        return $next($request);
    }

}
